package com.business.user;

import java.sql.*;
import com.sql.*;


public class PermissList
{
        private Connection conn=null;
        private Statement stmt=null;
        private ResultSet rs=null;
        private StringBuffer listString=new StringBuffer();

        public String Permisses()
        {
                try
                {
                        conn=DBFactory.getConnection();
                        stmt=conn.createStatement();
                         rs=stmt.executeQuery("select permission_name,permission_no from permission order by permissionid");
                        while(rs.next())
                                {
                                        listString.append(
                                                "<input type=\"checkbox\" name=\"checked\" value=\""+
                                                rs.getString(2)+"\">"
                                                +rs.getString(1)+"<br>");
                                                                           }
                        }catch(Exception e)
                {
                        e.printStackTrace();
                }
                finally
                {
                        try
                        {
                                rs.close();
                                stmt.close();
                                conn.close();
                        }
                        catch(SQLException sqlex)
                        {
                        }
                }
                return listString.toString();
        }

        public String rePermisses(String GroupNo)
        {
                StringBuffer listString=new StringBuffer();
                try
                {
                        conn=DBFactory.getConnection();
                                stmt=conn.createStatement();
                                rs=stmt.executeQuery(
                                        "select permission_name,permission_no from permission order by permissionid");
                                while(rs.next())
                                {
                                        String check="";
                                        String PermissionNo=rs.getString(2);
                                        Statement LinkStmt=conn.createStatement();
                                        ResultSet LinkRs=LinkStmt.executeQuery(
                                                "select * from grouppermissionlink where permission_no='"+
                                                PermissionNo+"' and group_no='"
                                                +GroupNo+"'");
                                        if(LinkRs.next())
                                        {
                                                check="checked";
                                        }
                                        else
                                        {
                                                check="";
                                        }
                                        listString.append(
                                                "<input type=\"checkbox\" name=\"checked\" value=\""+
                                                PermissionNo+"\""+check+">"
                                                +rs.getString(1)+"<br>");
                                }
                        }
                
                catch(Exception e)
                {
                        System.out.print(e.toString());
                }
                finally
                {
                        try
                        {
                                rs.close();
                                stmt.close();
                                conn.close();
                        }
                        catch(SQLException sqlex)
                        {
                        }
                }
                return listString.toString();
        }

}
